﻿hpxAdminApp.controller('enterpriseUserController', function ($scope, API_URL, NgTableParams, customerService, payingService) {

    $scope.filter = {

    };

    //获取所有企业用户
    $scope.tableParams = new NgTableParams({sorting: {'id': 'asc'}}, {
        getData: function (params) {
            console.log(params)
            return customerService.queryAllCustomer(params, $scope.filter).then(function (data) {
                $scope.first = $scope.getFirst(params);
                console.log(data)
                return data;
            });
        }
    });


    // 刷新
    $scope.reflash = function () {
        $scope.tableParams.reload();
    };

    // 显示详情
    $scope.show = function (item) {
        $scope.model = item;
        console.log(item);
        $('#modal-show').modal('show');
        // 获取操作员列表
        $scope.tableParams1 = new NgTableParams({ sorting: { 'id': 'asc' } }, {
            getData: function (params) {
                return customerService.getEnterpriseMember(1, item.id).then(function (data) {
                    $scope.first = $scope.getFirst(params);
                    console.log(data)
                    return data;
                });
            }
        });
        // 获取账户列表
        $scope.tableParams2 = new NgTableParams({ sorting: { 'id': 'asc' } }, {
            getData: function (params) {
                return payingService.getAccount(item.enterprise_id).then(function (data) {
                    $scope.first = $scope.getFirst(params);
                    console.log(data.acct_list)
                    return data;
                });
            }
        });
    };

    // 显示
    $scope.setLevel = function (item) {
        $scope.model = item;        //获取某条数据的详细信息        
        $('#modal-setLevel').modal('show');

    };

    // 保存修改客户等级信息
    $scope.saveCustomerLevel = function () {
        console.log($scope.model);
        customerService.setCustomerLevel($scope.model.id, {
            'customer_level_id': $scope.model.level,
        }).then(function (data) {
            confirm("客户等级信息修改成功。")
            $('#modal-setLevel').modal('hide');
        })
    }



});